package com.example.service.impl;

import com.example.mapper.ContractpayMapper;
import com.example.pojo.Indent;
import com.example.service.ContractpayService;
import com.example.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class ContractpayServiceImpl implements ContractpayService {
    @Autowired
    private ContractpayMapper contractpayMapper;

    @Override
    public List<Indent> getPayment(LocalDateTime date, HttpServletRequest request) {
        Integer idU = JwtUtils.parseJWT(request.getHeader("token")).get("id", Integer.class);
        List<Indent> list=contractpayMapper.getPayment(date,idU);
        return list;
    }

    @Override
    public List<Indent> getPaymentF(LocalDateTime date, HttpServletRequest request) {
        Integer idF = JwtUtils.parseJWT(request.getHeader("token")).get("id", Integer.class);
        List<Indent> list=contractpayMapper.getPaymentF(date,idF);
        return list;
    }


    @Override
    public List<Indent> getContractZK(String fname, HttpServletRequest request) {
        Integer idU = JwtUtils.parseJWT(request.getHeader("token")).get("id", Integer.class);
        List<Indent> list=contractpayMapper.getContractZk(fname,idU);
        return list;
    }

    @Override
    public List<Indent> getContractFJ(String name, HttpServletRequest request) {
        Integer idF = JwtUtils.parseJWT(request.getHeader("token")).get("id", Integer.class);
        LocalDateTime now = LocalDateTime.now();
        List<Indent> list=contractpayMapper.getContractFj(name,now,idF);
        return list;
    }

    @Override
    public List<Indent> getContractFL(String name, HttpServletRequest request) {
        Integer idF = JwtUtils.parseJWT(request.getHeader("token")).get("id", Integer.class);
        LocalDateTime now = LocalDateTime.now();
        List<Indent> list=contractpayMapper.getContractFL(name,now,idF);
        return list;
    }

    @Override
    public Indent getContractIdZk(Integer id, HttpServletRequest request) {
        Integer idU = JwtUtils.parseJWT(request.getHeader("token")).get("id", Integer.class);
        Indent indent=contractpayMapper.getContractIdZk(id,idU);
        return indent;
    }

    @Override
    public Indent getContractIdF(Integer id, HttpServletRequest request) {
        Integer idF = JwtUtils.parseJWT(request.getHeader("token")).get("id", Integer.class);
        Indent indent=contractpayMapper.getContractIdF(id,idF);
        return indent;
    }


}
